//
//  WhzTableViewCell.m
//  SingleSelection
//
//  Created by whz on 17/4/18.
//  Copyright © 2017年 王鸿政_whz. All rights reserved.
//

#import "WhzTableViewCell.h"

#define KLabelW 100
#define KLabelH self.contentView.frame.size.height
#define KImageViewX self.contentView.frame.size.width-50
#define KImageViewW 30
#define KImageViewH 30

@interface WhzTableViewCell ()

@property(nonatomic, strong)UILabel *whzLabel;
@property(nonatomic, strong)UIImageView *whzImageView;

@end

@implementation WhzTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createUI];
    }
    return self;
}

#pragma mark - method

- (void)createUI {

    [self.contentView addSubview:self.whzLabel];
    [self.contentView addSubview:self.whzImageView];
}

- (void)setDataDict:(NSDictionary *)dataDict {

    _dataDict = dataDict;
    
    _whzLabel.text = dataDict[@"nameID"];
    _whzImageView.image = [UIImage imageNamed:@"select"];
    
    [self isSelectImg];
}

- (void)isSelectImg {

    if ([_dataDict[@"isSelect"] isEqualToString:@"0"]) {
        
        _whzImageView.hidden = YES;
        
    } else {
    
        _whzImageView.hidden = NO;
    }
}

#pragma mark - lazyload

- (UILabel *)whzLabel {

    if (!_whzLabel) {
        
        _whzLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, KLabelW, KLabelH)];
        _whzLabel.textAlignment = NSTextAlignmentCenter;
        _whzLabel.textColor = [UIColor purpleColor];
        _whzLabel.font = [UIFont systemFontOfSize:18];
    }
    return _whzLabel;
}

- (UIImageView *)whzImageView {

    if (!_whzImageView) {
        
        _whzImageView = [[UIImageView alloc] initWithFrame:CGRectMake(KImageViewX, self.contentView.center.y-15, KImageViewW, KImageViewH)];
    }
    return _whzImageView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
